{% extends "base.html" %}

{% block headtitle %}Contributions to Corp tax{% endblock %}



{% block header_scripts %}
<script type="text/javascript" src="/m/js/lib/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="/m/css/jquery.dataTables.css" />
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="/m/css/jquery.cluetip.css" />
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="/m/css/jquery-ui-1.8.13.custom.css" />

<script type="text/javascript" src="/m/js/contrib_table.js"></script>
<script type="text/javascript" src="/m/js/lib/jquery.cluetip.js"></script>
<script type="text/javascript" src="/m/js/lib/jquery.ui.js"></script>
<script type="text/javascript">
FROM_DATE = "{{ from_date }}";
TO_DATE = "{{ to_date }}";
DAY = 1000 * 60 * 60 * 24;
WEEK = DAY * 7;
MONTH = DAY * 30;
YEAR = DAY * 365;
</script>
{% endblock %}



{% block breadcrumbs %}
<li><a href="/">Home</a></li>
<li><a href="/accounting">Accounting</a></li>
<li><a href="/accounting/contributions">Contributions</a></li>
{% endblock %}


{% block main_content %}
<h1 class="pagetitle">Contributions to Corp tax <span class="time">- last update {{ scan_date }}</span></h1>


<form id="search_form" class="search_form center">
	<label>Period</label>
	<select id="period_selector">
	    <option value="all" selected="selected">All Time</option>
	    <option value="week">Last Week</option>
	    <option value="month">Last Month</option>
	    <option value="year">Last Year</option>
	</select>

	<label for="from_date">From</label>
	<input type="text" id="from_date" name="from_date" value="{{ from_date }}"/>
	<label for="to_date">to</label>
	<input type="text" id="to_date" name="to_date" value="{{ to_date }}"/>

	<input type="button" class="button" id="refresh_table" value="Refresh" />
</form>

<script type="text/javascript">
$(function() {
    var dates = $( "#from_date, #to_date" ).datepicker({
        dateFormat: 'yy-mm-dd',
        defaultDate: "{{ to_date }}",
        changeMonth: true,
        numberOfMonths: 1,
        onSelect: function( selectedDate ) {
            var option = this.id == "from_date" ? "minDate" : "maxDate",
                instance = $( this ).data( "datepicker" ),
                date = $.datepicker.parseDate(
                    instance.settings.dateFormat ||
                    $.datepicker._defaults.dateFormat,
                    selectedDate, instance.settings );
            dates.not( this ).datepicker( "option", option, date );
        }
    });
});

$("#period_selector").change(function() {
    var period = $("#period_selector option:selected").val();
    if (period == "all") {
        $("#from_date").val(FROM_DATE);
        $("#to_date").val(TO_DATE);
    } else if (period == "week") {
        var date = $.datepicker.parseDate('yy-mm-dd', TO_DATE);
        date.setTime(date.getTime() - WEEK);
        $("#from_date").val($.datepicker.formatDate("yy-mm-dd", date));
        $("#to_date").val(TO_DATE);
    } else if (period == "month") {
        var date = $.datepicker.parseDate('yy-mm-dd', TO_DATE);
        date.setTime(date.getTime() - MONTH);
        $("#from_date").val($.datepicker.formatDate("yy-mm-dd", date));
        $("#to_date").val(TO_DATE);
    } else if (period == "year") {
        var date = $.datepicker.parseDate('yy-mm-dd', TO_DATE);
        date.setTime(date.getTime() - YEAR);
        $("#from_date").val($.datepicker.formatDate("yy-mm-dd", date));
        $("#to_date").val(TO_DATE);
    }
});

$(document).ready(function() {
    $("#refresh_table").click(function() {
        var params = {
            from_date: $("#from_date").val(),
            to_date: $("#to_date").val()
        };
        var value = $.get('/accounting/contributions/total/data', params, function(data) {
            $("#total_contribs").html(data);
        });
    });
});
</script>


<div class="center">
    <h2>Total tax income: <span class="credit" id="total_contribs">{{total_contribs|ecm_price}}</span> ISK</h2>
</div>

<table style="width: 100%;">
    <tr>
        <td style="padding: 10px;">
			<table class="table display" id="member_contrib_table">
			  <thead>
			    <tr>
			      <th class="top" scope="col" >Member</th>
			      <th class="top" scope="col" >Contributions</th>
			    </tr>
			  </thead>
			  <tbody>
			    <tr>
			      <td colspan="2" class="dataTables_empty">Loading data from server...</td>
			    </tr>
			  </tbody>
			  <tfoot>
			    <tr>
			      <th>Member</th>
			      <th>Contributions</th>
			    </tr>
			  </tfoot>
			</table>
        </td>
        <td style="padding: 10px;">
			<table class="table display" id="system_contrib_table">
			  <thead>
			    <tr>
			      <th class="top" scope="col" >Solar System</th>
			      <th class="top" scope="col" >Contributions</th>
			    </tr>
			  </thead>
			  <tbody>
			    <tr>
			      <td colspan="2" class="dataTables_empty">Loading data from server...</td>
			    </tr>
			  </tbody>
			  <tfoot>
			    <tr>
			      <th>Solar System</th>
			      <th>Contributions</th>
			    </tr>
			  </tfoot>
			</table>
        </td>
    </tr>
</table>

{% endblock %}
